import GameField from "@/views/cg/game/model/GameField.ts";
class Emitter {
  constructor() {
    this.handler = []
  }

  on(topic, handler){
    this.handler.push({
      topic,
      handler
    })
    return () => {
      this.handler.remove(x => x.handler === handler)
    }
  }

  emit(topic, data){
    this.handler
      .filter(x => x.topic === topic)
      .forEach((x) => x.handler(data));
  }
}

export default class Game{
  constructor() {
    this.timingHandlers = []
    this.emitter = new Emitter()
    this.field = new GameField(this)
    this.startAt = new Date().getTime()
  }
}